/*
 * kylin-os-manager
 *
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef DNSCheck_H
#define DNSCheck_H

#include <QObject>
#include <QProcess>
#include "DNSCheck_global.h"
#include "libBase.h"
#include "nw_check_tool_lib.h"
#include "dnscheckthread.h"
class DNSCHECK_EXPORT DNSCheck : public QObject, public LibBase
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID LibBaseInterfaceIID)
    Q_INTERFACES(LibBase)
public:
    DNSCheck(QObject *parent = 0);
    ~DNSCheck();
    //返回检测结果是否OK
    virtual CHECKRESULT getCheckResult() override;
    virtual void setInit() override;
public slots:
    virtual void startChecking(InnerNetCheck &checkSettings) override;
    //    void readCmdBashInfo();
    //    void readCmdBashInfoMore();
    //    void getDNSCheckResult(const QString &web);
    //    void getDNSCheckResult(const QList<QString> &list,int len);
    //    void slotCheckIsOver(CHECKRESULT result);
    void slotDnsCheckIsOver(statusStruct cur);
signals:
    void dnsCheckedFinished(int, CHECKRESULT);
    void processFinished();
    //    void sigCheckIsOver(CHECKRESULT);
    void sigDnsCheckIsStart(InnerNetCheck &checkSettings);

private:
    NWCheckToolLib *m_checkTool = nullptr;
    mutable QProcess *m_cmdProc = nullptr;
    mutable bool m_hasDNS = false;
    InnerNetCheck m_settings;
    mutable QString m_webSite;
    statusStruct m_cur;
    //    bool isContinue = true;

    QThread *mThread = nullptr;
    DnsCheckThread *mDnsCheckThread = nullptr;
private slots:
    //    void slotProcessOccurError();
};

#endif // DNSCheck_H
